<template>
  <div>
    <el-container class="wrap">
      <el-aside width="200px">
        <el-menu
          default-active="/"
          class="el-menu-vertical-demo"
          background-color="rgb(255,97,65)"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/">
            <i class="el-icon-star-off"></i>
            <span slot="title">首页</span>
          </el-menu-item>


          <div v-for="(item,index) in user.menus" :key="index">
            <!-- 目录 -->
            <el-submenu :index="item.id+''" v-if="item.children">
              <template slot="title">
                <i :class="item.icon"></i>
                <span>{{item.title}}</span>
              </template>
              <el-menu-item v-for="i in item.children" :key="i.id" :index="i.url">{{i.title}}</el-menu-item>
            </el-submenu>
            <!-- 菜单 -->
            <el-menu-item :index="item.url" v-else>{{item.title}}</el-menu-item>
          </div>


        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="smBox">
            <p>用户名：{{user.username}}</p>
            <el-button @click="goOut()">退出</el-button>
          </div>
        </el-header>
        <el-main>
          <!-- 面包屑 -->
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ $route.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
          <!-- 二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import {mapGetters,mapActions} from "vuex"
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      asyncUser:"asyncUser"
    }),
    // 点击退出
    goOut(){
      // 1、修改状态层
      this.asyncUser({})
      // 2、返回到登录页
      this.$router.push("/login")
    }
  },
  computed:{
    ...mapGetters({
      user:"user"
    })
  },
  components: {},
  mounted() {},
  destroyed() {},
};
</script>
<style scoped lang="less">
@import url("../../less/index.less");

.wrap {
  width: 100vw;
  height: 100vh;
}

.el-header {
  background-color: @color2;
}

.el-aside {
  background-color: @color1;
}

.el-main {
  background-color: @color4;
}

.smBox{
  float:right;
  margin-right: 50px;
}
</style>